﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QunYing.Web.market
{
    public partial class userinfo : System.Web.UI.Page
    {
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Repeater rp = ((Repeater) Master.FindControl("NavRepeater"));
                rp.DataSource = NavData();
                rp.DataBind();
            }
        }
        /// <summary>
        /// 快捷导航数据
        /// </summary>
        private DataTable NavData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("name");
            dt.Columns.Add("url");
            dt.Rows.Add("我的资料", "");
            return dt;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindUserInfo();
                ddlBind();
                BindDeviceInfo();
            }
        }
        /// <summary>
        /// 绑定下拉框
        /// </summary>
        private void ddlBind()
        {
            string userName = ((ArrayList)Session["userInfo"])[0].ToString();
            BLL.DeviceInfo info = new BLL.DeviceInfo();
            DataTable dt = info.QueryDevice(userName);
            ddlDevice.DataSource = dt;
            ddlDevice.DataTextField = "名称";
            ddlDevice.DataValueField = "ICSA编号";
            ddlDevice.DataBind();
        }
        /// <summary>
        /// 绑定信息
        /// </summary>
        private void BindUserInfo()
        {
            string strUserName = ((ArrayList)Session["userInfo"])[0].ToString();
            BLL.VipInfo info = new BLL.VipInfo();
            Model.VipInfo model = info.GetModelByID(strUserName);
            if (model == null)
            {
                return;
            }
            txtUserName.Text = model.用户姓名;
            txtVipId.Text = model.会员卡号;
            txtVipGrade.Text = model.会员级别;
            txtJoinTime.Text = model.入会时间.ToString("yyyy-MM-dd");
            txtEndTime.Text = model.到期时间.ToString("yyyy-MM-dd");
            txtEmail.Text = model.电邮地址;
            txtMobile.Text = model.移动电话;
            txtPhone.Text = model.固定电话;
            txtProvince.Text = model.所在省份;
            txtCity.Text = model.所在城市;
            txtAddress.Text = model.通信地址;
        }


        protected void ddlDevice_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindDeviceInfo();
        }

        /// <summary>
        /// 绑定水族箱信息
        /// </summary>
        private void BindDeviceInfo()
        {
            BLL.DeviceInfo info = new BLL.DeviceInfo();
            DataTable dt = info.QueryDeviceInfo(ddlDevice.SelectedValue);
            if (dt.Rows.Count == 0)
            {
                clearText();
                return;
            }
            txtIcsa.Text = dt.Rows[0]["ICSA编号"].ToString();
            txtCommunicate.Text = dt.Rows[0]["通信号码"].ToString();
            txtBrand.Text = dt.Rows[0]["品牌"].ToString();
            txtDeviceType.Text = dt.Rows[0]["型号"].ToString();
            txtDeviSize.Text = dt.Rows[0]["箱体尺寸"].ToString();
            txtFish.Text = dt.Rows[0]["鱼类品种"].ToString();
            txtGrass.Text = dt.Rows[0]["水草品种"].ToString();
            txtDeviceAddress.Text = dt.Rows[0]["水族箱地址"].ToString();
        }
        private void clearText()
        {
            txtIcsa.Text = string.Empty;
            txtCommunicate.Text = string.Empty;
            txtBrand.Text = string.Empty;
            txtDeviceType.Text = string.Empty;
            txtDeviSize.Text = string.Empty;
            txtFish.Text = string.Empty;
            txtGrass.Text = string.Empty;
            txtDeviceAddress.Text = string.Empty;
        }
    }
}
